package task;

import java.io.*;
import java.util.Scanner;

import static java.lang.System.exit;


public class Start {

//    static final String View = "C:\\Users\\86158\\Desktop\\数据结构课程设计文件夹\\View.txt";
//    static final String Administrator = "C:\\Users\\86158\\Desktop\\数据结构课程设计文件夹\\Administrator.txt";

    public static void userRun() throws IOException, ClassNotFoundException {

        ALGraph alGraph = new ALGraph();


        int num;
        while (1 == 1) {
            System.out.println("----------------------------");
            System.out.println("1.查看校园中的各个景点以及其详细信息");
            System.out.println("2.校园导航");
            System.out.println("3.显示各景点之间的路径以及距离");
            System.out.println("4.历史查询记录");
            System.out.println("0.退出系统");
            System.out.println("----------------------------");
            System.out.println("请输入对应的选项");
            Scanner scanner = new Scanner(System.in);
            num = scanner.nextInt();
            switch (num) {
                case 1:
                    alGraph.display();
                    break;
                case 2: {
                    System.out.println("-----------------");
                    System.out.println("请输入要查询的景点名字");
                    Scanner sc = new Scanner(System.in);
                    String start = sc.next();
                    System.out.println("请输入结束点景点名字");
                    String end = sc.next();
                    alGraph.dijkstra(start, end);
                    alGraph.HistoricalRecords(start,end);
                    break;
                }
                case 3:
                    alGraph.showWayLength();
                    break;
                case 4:
                    alGraph.HistoricalRecordsPrint();
                    break;
                case 0:
                    exit(0);
            }


        }


    }

    public static void administratorRun() throws IOException, ClassNotFoundException {
        //以下操作初始化邻接表

        Administrators administrator1 = new Administrators("root", "123456");
        Administrators administrator2 = new Administrators("111", "123456");
        Administrators administrator3 = new Administrators("222", "123456");
        LinkList linkList = new LinkList<>();
        linkList.add(administrator1);
        linkList.add(administrator2);
        linkList.add(administrator3);
        ALGraph alGraph = new ALGraph();
        while (true) {
            System.out.println("欢迎来到管理员页面");
            System.out.println("-----------------");
            System.out.println("请输入管理员账号");
            Scanner scanner1 = new Scanner(System.in);
            String username = scanner1.nextLine();
            System.out.println("请输入管理员密码");
            String password = scanner1.nextLine();
            Administrators administrators = new Administrators(username, password);
            if (linkList.isCorrect(administrators)) {
                System.out.println("登陆成功");
                break;
            } else {
                System.out.println("登陆失败,密码错误");
            }
        }
        boolean flag = true;
        while (flag) {
            System.out.println("-----------------------");
            System.out.println("1.增加一个景点");
            System.out.println("2.删除一个景点");
            System.out.println("3.更新一个景点");
            System.out.println("输入其他数字退出");
            System.out.println("请选择对应的选项");
            Scanner scanner2 = new Scanner(System.in);
            int Num1 = scanner2.nextInt();
            switch (Num1) {
                case 1:
                    View newView = new View();
                    Scanner sc = new Scanner(System.in);
                    System.out.println("请输入景点名字");
                    String name = sc.nextLine();
                    newView.setViewName(name);
                    System.out.println("请输入景点的details");
                    String details = sc.nextLine();
                    newView.setDetails(details);
                    System.out.println("请输入景点建成的时间");
                    Integer year = sc.nextInt();
                    newView.setYear(year);
                    alGraph.add(newView);
                    break;

                case 2: {
                    System.out.println("---------------");
                    Scanner scanner3 = new Scanner(System.in);
                    System.out.println("请输入景点的名称");
                    String deleteName = scanner3.nextLine();
                    alGraph.delete(deleteName);
                    break;
                }
                case 3: {
                    System.out.println("你要更新的内容？");
                    System.out.println("1.景点的名字/详情信息/年份");
                    System.out.println("2.景点相邻的景点距离");
                    System.out.println("输入其他内容返回上一层");
                    Scanner scanner4 = new Scanner(System.in);
                    int i = scanner4.nextInt();
                    if (i == 1) {
                        View view = new View();
                        Scanner scanner5 = new Scanner(System.in);
                        Scanner scanner3 = new Scanner(System.in);
                        System.out.println("请输入要修改的景点的名字");
                        String index = scanner3.next();
                        System.out.println("请输入景点名字");
                        String Name = scanner5.nextLine();
                        view.setViewName(Name);
                        System.out.println("请输入景点的详情信息");
                        String Details = scanner5.nextLine();
                        view.setDetails(Details);
                        System.out.println("请输入景点建成的时间");
                        Integer Year = scanner5.nextInt();
                        view.setYear(Year);
                        alGraph.updateView(index, view);
                    }
                    if (i == 2) {
                        System.out.println("请输入要修改两个景点的名字");
                        Scanner scanner5 = new Scanner(System.in);
                        String updateView1 = scanner5.nextLine();
                        String updateView2 = scanner5.nextLine();
                        Scanner scanner3 = new Scanner(System.in);
                        System.out.println("请输入新修改的距离");
                        int info = scanner3.nextInt();
                        alGraph.updateView(updateView1, updateView2, info);
                    }
                    break;
                }
                default:
                    flag = false;
            }

        }
    }
}

